{{extend './_layouts/home.html'}}
{{block 'body'}}
<form id="login_form">
邮箱：
<input type="text" name="login_email">
<br>
密码：
<input type="text" name="login_password">
<br>
<button id="loging_btn" tyep="submit">登录</button>
</form>
{{/block}}

{{block 'link'}}
<link rel="stylesheet" href="/public/css/login.css">
{{/block}}
{{block 'script'}}
<script src="/node_modules/jquery/dist/jquery.min.js"></script>
<script >
    
    var login_form=document.querySelector('#login_form')
    login_form.addEventListener('submit',function(e){
        e.preventDefault()
        var login_data=$(this).serialize();
        
        $.ajax({
            url:'/login',
            type:'post',
            dataType:'json',
            data:login_data,
            success:function(data){
                let err_code =data.err_code
                if(err_code==500){
                    console.log(data.message);
                    window.alert('服务器繁忙，请稍后重试')
                }
                else if(err_code ==1){
                    window.alert(
                        '密码或者邮箱不正确，请重新输入'
                    )
                }
                else if (err_code ==0){
                window.location.href='/'
                }
            },
        error:function(err){
            console.log(err.message);
        }
        })
    })
</script>
{{/block}}